<script>
    function ajax_refresh_publications_table()
    {
        $.ajax( 'refresh_publications_table', {
               data: {
                   'csrfmiddlewaretoken': '{{ csrf_token }}',
               },
               type: 'post',
               success: function(result) {
                   // success code execution here
                   $('#ajax_placeholder_table').html(result); // Update UI.
               },
               error: function(xhr,status,error) {
                   // error code here
               },
               complete: function(xhr,status) {
                   // completion code here
               }
        });
    }

    function ajax_delete_publication(publication_id)
    {
        $('#del_'+publication_id+'_btn').prop("disabled", true);
        $.ajax( '/delete_publication', {
           data: {
               'csrfmiddlewaretoken': '{{ csrf_token }}',
               'publication_id': publication_id
           },
           type: 'post',
           success: function(result) {
                // success code execution here
                if (result.status == 'success')
                {
                     ajax_refresh_publications_table();
                }
           },
           error: function(xhr,status,error) {
                // error code here
           },
           complete: function(xhr,status) {
                // completion code here
                $('#del_'+publication_id+'_btn').prop("disabled", false);
           }
         });
    }

    function popup_publication_modal(publication_id)
    {
        $('#publish_'+publication_id+'_btn').prop("disabled", true);
       
        $.ajax( 'my_publication_modal', {
            data: {
               'csrfmiddlewaretoken': '{{ csrf_token }}',
               'publication_id' : publication_id
            },
            type: 'post',
            success: function(result) {
               // success code execution here
               $('#ajax_modal').html(result);
               $('#publication_modal').modal();
            },
            error: function(xhr,status,error) {
               // error code here
            },
            complete: function(xhr,status) {
               // completion code here
            }
        });
    }
</script>